package fair.controller;

import fair.entity.Result;
import fair.pojo.Record;
import fair.service.IRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author fair_wu
 * @version v1.0
 * @date 2021-03-06 下午 18:20
 */
@Api(tags = "日志管理")
@RestController
@RequestMapping("log")
public class LogController {

    @Reference(version = "${dubbo.service.core.version}", group = "${dubbo.service.core.group}", timeout = 100000)
    private IRecordService recordService;

    /**
     * 分页查询系统日志
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    @ApiOperation("日志查询")
    public Result getLogs(@RequestParam(value = "pageNum", defaultValue = "1") String pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "10") String pageSize){
        try {
            List<Record> records = recordService.findByPage(pageNum, pageSize);
            return new Result(0, "", records);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(500, "内部异常");
        }
    }
}
